package com.tutu.commons.utils;


import org.springframework.validation.BindingResult;

/**
 * @Program: b2c-cloud-store
 * @Description: 获取校验参数的异常信息
 * @Author: JK.TuTu
 * @ @Version: 1.0
 * @Create: 2022-12-13 23:21
 **/
public class CollectError {
    /**
     * 收集JSR303校验参数的异常message信息
     * @param result 校验返回异常信息
     * @return 返回所有异常的字符串
     */
    public static String getErrorInfo(BindingResult result) {
        StringBuilder errorIfo = new StringBuilder();
        result.getAllErrors().forEach((item) -> {
            errorIfo.append(item.getDefaultMessage()).append(",");
        });
        return errorIfo.toString();
    }
}
